package edu.njust.cma.mapper;

import edu.njust.cma.DTO.SubTaskForLab;
import edu.njust.cma.pojo.SubtaskSample;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Insert;

import java.util.List;

@Mapper
public interface SubtaskSampleMapper {
    @Select("select * from subtasks_samples where task_id=#{taskId}")
    SubtaskSample getSubtaskSample(Integer taskId);

    @Insert("insert into subtasks_samples(task_id,sample_name,sample_model,batch_number,sample_manager_id,user_id) " +
            "values(#{taskId},#{sampleName},#{sampleModel},#{batchNumber},#{sampleManagerId},#{userId})")
    void insert(SubtaskSample subtaskSample);


    @Select("select * from subtask_samples where user_id=#{userId}")
    SubtaskSample getSubtaskSampleByUserId(Integer userId);

    //TODO 根据ID查,添加样本名称,样本型号,样品批号,样品负责人,样品照片
    @Update("update subtasks_samples set sample_name=#{sampleName},sample_model=#{sampleModel},batch_number=#{batchNumber}," +
            "sample_manager_id=#{sampleManagerId},sample_photo=#{samplePhoto} where id=#{id}")
    void submitSample(@Param("taskId")int taskId
            ,@Param("sampleName") String sampleName
            ,@Param("sampleModal") String sampleModal
            ,@Param("sampleBatch") String sampleBatch
            ,@Param("samplePrincipal") String samplePrincipal
            ,@Param("samplePhoto") String samplePhoto);


    @Update("update subtasks_samples set status=#{status} where id=#{id}")
    void updateStatus(Integer id, int status);

    @Select("select status from subtasks_samples where task_id=#{taskId}")
    int getStatus(Integer taskId);

    @Select("select * from subtasks_samples where user_id=#{userId}")
    List<SubtaskSample> getSampleTaskByUserId(int userId);

    @Select("select * from subtasks_samples where task_id=#{taskId}")
    SubtaskSample getSubtaskSampleByTaskId(int taskId);

    @Update("update subtasks_samples set submission_time=#{nowTime} where id=#{id}")
    void updateTimeById(int id, String nowTime);

    @Update("update subtasks_samples set sample_photo_url=#{samplePhotoUrl} where id=#{id}")
    void updateUrlById(int id, String samplePhotoUrl);
}
